class Observer {
	constructor(data) {
		this.walk(data)
	}

	walk(data) {
		if(!data || typeof data !== 'object') {
			return;
		}
		Object.keys(data).forEach(key => {
			this.defineReactive(data, key, data[key])
		})
	}
	
//	data: {
//		name: "kds",
//		msg: "今晚来仙湖",
//		person: {
//			name: "zs"
//		}
//	}
	
	defineReactive(data, key, val) {
		let _this = this;
		let dep = new Dep();
		this.walk(val);
		Object.defineProperty(data, key, {
			enumerable: true,
			configurable: true,
			get() {
				Dep.target && dep.addSub(Dep.target)
				return val
			},
			set(newVal) {
				if(newVal == val) {
					return
				}
				val = newVal;
				_this.walk(newVal);
				dep.notify()
			}
		})
	}
}